//
// Created by Administrator on 2020/7/8.
//T4章小结:
//回顾:
//1.对象的生存期、作用域与可见性
//2.类的静态成员
//3.数据共享与保护
//4.友元
//5.编译预处理命令
//6.多文件结构与工程

//实验1
//观察x,y值变化
/*
#include <iostream>
using namespace std;
void fn1();
int x=1,y=2;
int main()
{
    cout<<"Begin..."<<endl;
    cout<<"x="<<x<<endl;
    cout<<"y="<<y<<endl;

    cout<<"Evaluate x and y in main()..."<<endl;
    int x=10,y=20;
    cout<<"x="<<x<<endl;
    cout<<"y="<<y<<endl;

    cout<<"Step into fn1()"<<endl;
    fn1();

    cout<<"Back into main"<<endl;
    cout<<"x="<<x<<endl;
    cout<<"y="<<y<<endl;

    return 0;
}
void fn1()
{
    int y=200;
    cout<<"x="<<x<<endl;
    cout<<"y="<<y<<endl;
}
*/
//实验2
//实现客户机(CLIENT)类:
//1.声明字符型静态数据成员ServerName,保存其服务器名称;
//2.整型静态数据成员ClientNum,记录已定义的客户数量;
//3.定义静态函数ChangeServerName()改变服务器名称

//1-在头文件client.h中声明类
//2-在文件client.cpp中实现
//3-在文件test.cpp中测试这个类
//4-观察相应的成员变量取值的变化情况
//-------------在头文件client.h中声明类--------------//
#ifndef CLIENT_H_
#define CLIENT_H_
class Client
{
    static char ServerName;
    static int ClientNum;
public:
    static void ChangeServerName(char name);
    static int getClientNum();
};
//-------------在文件client.cpp中实现--------------//

#include "stdafx.h"
#include "client.h"
void Client::ChangeServerName(char name)
{
    Client::ServerName=name;
    Client::ClientNum++;
}
int Client::getClientNum()
{
    return Client::ClientNum;
}
//-------------在文件test.cpp中测试这个类--------------//
#include <iostream>
#include "client.h"
using namespace std;

int Client::ClientNum=0;
char Client::ServerName='a';
int main()
{
    Client c1;
    c1.ChangeServerName('a');
    cout<<c1.getClientNum()<<endl;

    Client c2;
    c2.ChangeServerName('b');
    cout<<c2.getClientNum()<<endl;
    return 0;
}

